<style type="text/css">

    body {
        height: 595px;
        width: 842px;
        /* to centre page on screen*/
        margin-left: auto;
        margin-right: auto;
    }

.etiqueta{width:80mm;height:75mm;overflow:hidden;}
.hoja{width:290mm;height:180mm;overflow:hidden;}
/*

.tablas{width:98%;height:98%;}

.month{
        font-family:  sans-serif;
        font-size: 48px;
        text-align:center;
      }
.dia_semana{text-align: center; height: 10mm;}*/
</style>

<?php
App::import('Vendor','tcpdf/tcpdf');
ob_end_clean();
$tcpdf = new TCPDF();
$textfont = 'helvetica';

$tcpdf->SetAuthor("RO-MA");
$tcpdf->SetAutoPageBreak(true);
$tcpdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$tcpdf->setPrintHeader(false);
$tcpdf->setPrintFooter(false);
 
$tcpdf->SetTextColor(0, 0, 0);
$tcpdf->SetFont($textfont,'',8);
    $tcpdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

$style = array(
    'position' => '',
    'align' => 'C',
    'stretch' => false,
    'fitwidth' => true,
    'cellfitalign' => '',
    'border' => true,
    'hpadding' => 'auto',
    'vpadding' => 'auto',
    'fgcolor' => array(0,0,0),
    'bgcolor' => false, //array(255,255,255),
    'text' => true,
    'font' => 'helvetica',
    'fontsize' => 8,
    'stretchtext' => 2
);
$tarjeta=1;

foreach ($service_order_rows as $order): 
    if (($tarjeta == 1) or ($tarjeta == 3) or ($tarjeta == 5) or ($tarjeta == 7)) {
        $tcpdf->AddPage('L', 'A4');        
    }
    $htmlcontent = '';
    //Generación del codigo de barra
    $cod_barra = 'codigobarra';
    $codigo = $tcpdf->serializeTCPDFtagParameters(array($order['ServiceOrderRow']['id'], 'C39', '', '', 50, 20, 0.4, array('position'=>'S', 'border'=>true, 'padding'=>1, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'courier', 'fontsize'=>7, 'stretchtext'=>4), 'N'));
    // create some HTML content




    $htmlcontent1 = '<table style="float:left" border="1" cellspacing="2" cellpadding="0" class="etiqueta">
        <tr><td width="100%"; height="40%"; align="center" colspan="4"><h2>ORDEN DE RECEPCION: '.$service_order['ServiceOrder']['numero_orden_de_servicio'].' - '.$order['ServiceOrderRow']['unidad'].'</h2></td></tr>
        <tr><th bgcolor="#cccccc" align="center" colspan="4"><p><span style="font-size: 25; font-weight: bold;">Cubierta Nro: '.$order['ServiceOrderRow']['id'].'</span></p></th></tr>
        <tr><td align="center" colspan="4"><tcpdf align="center" method="write1DBarcode" params="'.$codigo.'"/></td></tr>
        <tr>
            <td bgcolor="#cccccc" align="center" colspan="1">TIPO</td>
            <td bgcolor="#cccccc" align="center" colspan="1">MEDIDA</td>
            <td bgcolor="#cccccc" align="center" colspan="1">MARCA</td>
            <td bgcolor="#cccccc" align="center" colspan="1">NRO SERIE</td>
        </tr>
        <tr>
            <td align="center" colspan="1">'.$order['ServiceOrderRow']['tipo'].'</td>
            <td align="center" colspan="1">'.$order['ServiceOrderRow']['medida'].'</td>
            <td align="center" colspan="1">'.$order['CubiertaMarca']['nombre'].'</td>
            <td align="center" colspan="1">'.$order['ServiceOrderRow']['numero_de_serie'].'</td>
        </tr>
        <tr><td align="center" colspan="4"><p><span style="font-size: 25; font-weight: bold;">' . $service_order['Client']['nombre'] .'</span></p></td></tr>
        
    </table>';
    $htmlcontent2 = '<table style="float:left" border="1" cellspacing="2" cellpadding="0" class="etiqueta">
        <tr><td width="100%"; height="40%"; align="center" colspan="4"><h2>ORDEN DE RECEPCION: '.$service_order['ServiceOrder']['numero_orden_de_servicio'].' - '.$order['ServiceOrderRow']['unidad'].'</h2></td></tr>
        <tr><th bgcolor="#cccccc" align="center" colspan="4"><p><span style="font-size: 25; font-weight: bold;">Cubierta Nro: '.$order['ServiceOrderRow']['id'].'</span></p></th></tr>
        <tr><td align="center" colspan="4"><tcpdf align="center" method="write1DBarcode" params="'.$codigo.'"/></td></tr>
        <tr>
            <td bgcolor="#cccccc" align="center" colspan="1">TIPO</td>
            <td bgcolor="#cccccc" align="center" colspan="1">MEDIDA</td>
            <td bgcolor="#cccccc" align="center" colspan="1">MARCA</td>
            <td bgcolor="#cccccc" align="center" colspan="1">NRO SERIE</td>
        </tr>
        <tr>
            <td align="center" colspan="1">'.$order['ServiceOrderRow']['tipo'].'</td>
            <td align="center" colspan="1">'.$order['ServiceOrderRow']['medida'].'</td>
            <td align="center" colspan="1">'.$order['CubiertaMarca']['nombre'].'</td>
            <td align="center" colspan="1">'.$order['ServiceOrderRow']['numero_de_serie'].'</td>
        </tr>
        <tr><td align="center" colspan="4"><p><span style="font-size: 25; font-weight: bold;">' . $service_order['Client']['nombre'] .'</span></p></td></tr>
        
    </table>';
     $htmlcontent = '<body>
                        <div id="hoja" class="tablas">
                            <table border="1">
                            <tr>
                                <td width="44%">'.$htmlcontent1.'</td>
                                <td width="4%"> </td>
                                <td width="51%">'.$htmlcontent2.'</td>
                            </tr>
                            </table>
                        </div>
                    </body>';    
    $tcpdf->writeHTML($htmlcontent, true, 0, true, 0);

    if (($tarjeta == 1) or ($tarjeta == 3) or ($tarjeta == 5) or ($tarjeta == 7))
    {
        $htmlcontent = "<br /><br />------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br /><br />";
        $tcpdf->writeHTML($htmlcontent, true, 0, true, 0);
    }

    $tarjeta++;
endforeach;
unset($order);

 
// output the HTML content
//$tcpdf->writeHTML($htmlcontent, true, 0, true, 0);
//$tcpdf->writeHTML($html, true, false, true, false, '');
//$tcpdf->writeHTML($contenido, true, 0, true, 0);
//$tcpdf->LastPage();
$tcpdf->Output('miPdf.pdf', 'I');
?>